/**
 * @param {number[][]} edges
 * @return {number}
*/
var findCenter = function(edges) {
  let map = new Map();
  for(let i = 0; i < edges.length; i++) {
    map.has(edges[i][0]) ? map.set(edges[i][0], map.get(edges[i][0]) + 1) : map.set(edges[i][0], 1);
    map.has(edges[i][1]) ? map.set(edges[i][1], map.get(edges[i][1]) + 1) : map.set(edges[i][1], 1);
  }
  let result = [...map].sort((a, b) => b[1] - a[1])
  return result[0][0];
};
let edges = [[1,2],[2,3],[4,2]];
console.log(findCenter(edges));
edges = [[1,2],[5,1],[1,3],[1,4]];
console.log(findCenter(edges));
